<%@ page import="service.serviceimpl.ServiceUserImpl" %>
<%@ page import="entity.Userinfo" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    String op = request.getParameter("op");
    if(op!=null){
        ServiceUserImpl serviceUser = new ServiceUserImpl();
        if(op.equals("delete")){
            int id = Integer.parseInt(request.getParameter("id"));
            int i = serviceUser.executeUpdate("delete from userinfo where id=?", id);
            if(i>0){
                request.getRequestDispatcher("main.jsp?isdelete=t").forward(request,response);
            }else{
                response.sendRedirect("main.jsp?delete=t");
            }

        }else if(op.equals("add")){
            int age = Integer.parseInt(request.getParameter("age"));
            int sex = Integer.parseInt(request.getParameter("sex"));
            String name=request.getParameter("name");

            int i = serviceUser.executeUpdate("insert into userinfo(name,sex,age,ranking,dept) values(?,?,?,'1','总裁')",name,sex,age);
            if(i>0){
                request.getRequestDispatcher("main.jsp?isadd=t").forward(request,response);
            }else{
                response.sendRedirect("main.jsp?add=t");
            }

        }else if(op.equals("update1")){
            int id = Integer.parseInt(request.getParameter("id"));
            request.getRequestDispatcher("update.jsp?id="+id).forward(request,response);
        }else if(op.equals("update2")){
            int id = Integer.parseInt(request.getParameter("id"));
            String dept = request.getParameter("dept");
            int sex = Integer.parseInt(request.getParameter("sex"));
            String name=request.getParameter("name");
            int i = serviceUser.executeUpdate("update userinfo set name=?,sex=?,dept=? where id=?", name, sex, dept, id);
            if(i>0){
                request.getRequestDispatcher("main.jsp?isupdate=t").forward(request,response);
            }else{
                response.sendRedirect("main.jsp?update=t");
            }
        }


    }else{
        response.sendRedirect("main.jsp?feifa=t");
    }

%>

</body>
</html>
